package TV; /**
 * Created by stjj on 2022/9/14.
 */

import io.appium.java_client.MobileElement;
import io.appium.java_client.TouchAction;
import io.appium.java_client.android.AndroidDriver;
import io.appium.java_client.touch.WaitOptions;
import io.appium.java_client.touch.offset.PointOption;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.openqa.selenium.remote.DesiredCapabilities;

import java.net.MalformedURLException;
import java.net.URL;
import java.time.Duration;
import java.util.Set;

public class TvKanBan {
    private AndroidDriver driver;

    @Before
    //夜神：127.0.0.1:62001
    //雷电：emulator:5554
    public void setUp() throws MalformedURLException {
        DesiredCapabilities desiredCapabilities = new DesiredCapabilities();
        desiredCapabilities.setCapability("platformName", "Android");
        desiredCapabilities.setCapability("appium:platformVersion", "7.1.2");
        desiredCapabilities.setCapability("appium:deviceName", "127.0.0.1:5556");
        desiredCapabilities.setCapability("appium:appPackage", "com.mingdao.ews2");
        desiredCapabilities.setCapability("appium:appActivity", "com.dtr.zxing.activity.MainActivity");
        desiredCapabilities.setCapability("appium:noReset", false);
        desiredCapabilities.setCapability("appium:automationName", "UiAutomator1");
        desiredCapabilities.setCapability("appium:ensureWebviewsHavePages", true);
        desiredCapabilities.setCapability("appium:nativeWebScreenshot", true);
        desiredCapabilities.setCapability("appium:newCommandTimeout", 3600);
        desiredCapabilities.setCapability("appium:connectHardwareKeyboard", true);

        URL remoteUrl = new URL("http://127.0.0.1:4723/wd/hub");

        driver = new AndroidDriver(remoteUrl, desiredCapabilities);
    }

    @Test
    public void sampleTest() throws InterruptedException {
        try {
            Thread.sleep(10000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        driver.context("WEBVIEW_com.mingdao.ews2");
        MobileElement el1 = (MobileElement) driver.findElementByXPath("//*[@id=\"app\"]/div/div/div/div[2]/div[1]/input");
        el1.sendKeys("dehe");
        Thread.sleep(5000);
        driver.pressKeyCode(20);
        MobileElement el2 = (MobileElement) driver.findElementByXPath("//*[@id=\"app\"]/div/div/div/div[2]/div[2]/input");
        el2.sendKeys("Abc123456");
        Thread.sleep(5000);
        driver.pressKeyCode(20);
        driver.pressKeyCode(66);
        Thread.sleep(4000);
        for (int i = 1; i <= 7 ; i++) {
            driver.pressKeyCode(20);
            Thread.sleep(1000);
        }
        driver.pressKeyCode(66);
        Thread.sleep(4000);
        driver.context("NATIVE_APP");
        driver.findElementByAndroidUIAutomator("text(\"生产任务进度看板\")");
        try {
            Thread.sleep(6000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }

    }

    @After
    public void tearDown() {
        driver.quit();
    }

}
